#include<iostream>
#include<cstdio>
using namespace std;
int n,m,b[100000],sum,q;
int getf(int i){
	if(b[i]==i)return i;
	else b[i]=getf(b[i]); 
	return b[i];
}
void merge(int x,int y){
	int t1=getf(x),t2=getf(y);
	if(t1!=t2)b[t2]=b[t1];
	return;
}
int read(){
	int num=0;
	char c=getchar();
	while(c>'9'||c<'0')c=getchar();
	while(c>='0'&&c<='9'){
		num*=10;
		num+=c-'0';	
		c=getchar();
	}
	return num;
}
int main(){
	freopen("relations.in","r",stdin);
	freopen("relations.out","w",stdout);
	n=read();m=read();
	for(int i=1;i<=n;i++)b[i]=i;
	for(int x,y,i=1;i<=m;i++){
		x=read();
		y=read();
		merge(x,y);
	}
	for(int i=1;i<=n;i++)b[i]=getf(i);
	q=read();
	for(int i=1,x,y;i<=q;i++){
		scanf("%d%d",&x,&y);
		if(b[x]==b[y])cout<<"Yes\n";
		else cout<<"No\n";
	}
	return 0;
}
